home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 February / PCWFEB08.iso / Software / Resources / Utilities / Partition Logic 0.68 / partlogic-0.68.iso / system / headers / sys / ext.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-10  |  9.1 KB  |  266 lines

  1. // 
  2. //  Visopsys
  3. //  Copyright (C) 1998-2007 J. Andrew McLaughlin
  4. //  
  5. //  This library is free software; you can redistribute it and/or modify it
  6. //  under the terms of the GNU Lesser General Public License as published by
  7. //  the Free Software Foundation; either version 2.1 of the License, or (at
  8. //  your option) any later version.
  9. //
  10. //  This library is distributed in the hope that it will be useful, but
  11. //  WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
  13. //  General Public License for more details.
  14. //
  15. //  You should have received a copy of the GNU Lesser General Public License
  16. //  along with this library; if not, write to the Free Software Foundation,
  17. //  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. //
  19. //  ext.h
  20. //
  21.  
  22. // This file contains definitions and structures for using and manipulating
  23. // EXT2 and EXT3 filesystems in Visopsys.  The reference material for this
  24. // header can be found at: http://www.nongnu.org/ext2-doc/ext2.html
  25.  
  26. #if !defined(_EXT_H)
  27.  
  28. /*
  29.   The organisation of an ext2 file system on a floppy:
  30.  
  31.   offset # of blocks description
  32.   -------- ----------- -----------
  33.   0                  1 boot record
  34.   -- block group 0 --
  35.   (1024 bytes)       1 superblock
  36.   2                  1 group descriptors
  37.   3                  1 block bitmap
  38.   4                  1 inode bitmap
  39.   5                 23 inode table
  40.   28              1412 data blocks
  41.  
  42.   The organisation of a 20MB ext2 file system:
  43.  
  44.   offset # of blocks description
  45.   -------- ----------- -----------
  46.   0                  1 boot record
  47.   -- block group 0 --
  48.   (1024 bytes)       1 superblock
  49.   2                  1 group descriptors
  50.   3                  1 block bitmap
  51.   4                  1 inode bitmap
  52.   5                214 inode table
  53.   219             7974 data blocks
  54.   -- block group 1 --
  55.   8193               1 superblock backup
  56.   8194               1 group descriptors backup
  57.   8195               1 block bitmap
  58.   8196               1 inode bitmap
  59.   8197             214 inode table
  60.   8408            7974 data blocks
  61.   -- block group 2 --
  62.   16385              1 block bitmap
  63.   16386              1 inode bitmap
  64.   16387            214 inode table
  65.   16601           3879 data blocks
  66. */
  67.  
  68. // Definitions
  69.  
  70. // Superblock-related constants
  71. #define EXT_SUPERBLOCK_SECTOR    2
  72. #define EXT_MAGICNUMBER          0xEF53
  73.  
  74. // EXT_ERRORS values for the 'errors' field in the superblock
  75. #define EXT_ERRORS_CONTINUE      1  // Continue as if nothing happened
  76. #define EXT_ERRORS_RO            2  // Remount read-only
  77. #define EXT_ERRORS_PANIC         3  // Cause a kernel panic
  78. #define EXT_ERRORS_DEFAULT       EXT_ERRORS_CONTINUE
  79.  
  80. // EXT_OS: 32-bit identifier of the OS that created the file system for
  81. // the 'creator_os' field in the superblock
  82. #define EXT_OS_LINUX             0          // Linux
  83. #define EXT_OS_HURD              1          // Hurd
  84. #define EXT_OS_MASIX             2          // MASIX
  85. #define EXT_OS_FREEBSD           3          // FreeBSD
  86. #define EXT_OS_LITES4            4          // Lites
  87. #define EXT_OS_VISOPSYS          0xA600D05  // Visopsys
  88.  
  89. // 32-bit revision level value for the 'rev_level' field in the superblock
  90. #define EXT_GOOD_OLD_REV         0  // Original format
  91. #define EXT_DYNAMIC_REV          1  // V2 format with dynamic inode sizes
  92.  
  93. // Superblock flags
  94. #define EXT_ROCOMPAT_SPARSESUPER 0x01
  95. #define EXT_ROCOMPAT_LARGEFILE   0x02
  96. #define EXT_ROCOMPAT_BTREEDIR    0x04
  97. #define EXT_ROCOMPAT_ANY         0xffffffff
  98.  
  99. // If the revision level (above) is EXT_GOOD_OLD_REV, here are a coupla
  100. // fixed values
  101. #define EXT_GOOD_OLD_FIRST_INODE 11
  102. #define EXT_GOOD_OLD_INODE_SIZE  128
  103.  
  104. // File system states
  105. #define EXT_VALID_FS             1  // Unmounted cleanly
  106. #define EXT_ERROR_FS             2  // Errors detected
  107.  
  108. // Reserved inode numbers for the inode table
  109. #define EXT_BAD_INO              1  // Bad blocks inode
  110. #define EXT_ROOT_INO             2  // Root directory inode
  111. #define EXT_ACL_IDX_INO          3  // ACL index inode
  112. #define EXT_ACL_DATA_INO         4  // ACL data inode
  113. #define EXT_BOOT_LOADER_INO      5  // Boot loader inode
  114. #define EXT_UNDEL_DIR_INO        6  // Undelete directory inode
  115.  
  116. // File types for the file_type field in extDirectoryEntry
  117. #define EXT_FT_UNKNOWN           0
  118. #define EXT_FT_REG_FILE          1
  119. #define EXT_FT_DIR               2
  120. #define EXT_FT_CHRDEV            3
  121. #define EXT_FT_BLKDEV            4
  122. #define EXT_FT_FIFO              5
  123. #define EXT_FT_SOCK              6
  124. #define EXT_FT_SYMLINK           7
  125. #define EXT_FT_MAX               8
  126.  
  127. // EXT_S_: 16-bit value used to indicate the format of the described file
  128. // and the access rights for the i_mode field in extInode
  129. //                 -- file format --
  130. #define EXT_S_IFMT               0xF000  // Format mask
  131. #define EXT_S_IFSOCK             0xC000  // Socket
  132. #define EXT_S_IFLNK              0xA000  // Symbolic link
  133. #define EXT_S_IFREG              0x8000  // Regular file
  134. #define EXT_S_IFBLK              0x6000  // Block device
  135. #define EXT_S_IFDIR              0x4000  // Directory
  136. #define EXT_S_IFCHR              0x2000  // Character device
  137. #define EXT_S_IFIFO              0x1000  // Fifo
  138. //                 -- access rights --
  139. #define EXT_S_ISUID              0x0800  // SUID
  140. #define EXT_S_ISGID              0x0400  // SGID
  141. #define EXT_S_ISVTX              0x0200  // Sticky bit
  142. #define EXT_S_IRWXU              0x01C0  // User access rights mask
  143. #define EXT_S_IRUSR              0x0100  // Read
  144. #define EXT_S_IWUSR              0x0080  // Write
  145. #define EXT_S_IXUSR              0x0040  // Execute
  146. #define EXT_S_IRWXG              0x0038  // Group access rights mask
  147. #define EXT_S_IRGRP              0x0020  // Read
  148. #define EXT_S_IWGRP              0x0010  // Write
  149. #define EXT_S_IXGRP              0x0008  // Execute
  150. #define EXT_S_IRWXO              0x0007  // Others access rights mask
  151. #define EXT_S_IROTH              0x0004  // Read
  152. #define EXT_S_IWOTH              0x0002  // Write
  153. #define EXT_S_IXOTH              0x0001  // Execute
  154.  
  155. // Values for the 'flags' field in extInode
  156. #define EXT_SECRM_FL             0x00000001  // Secure deletion
  157. #define EXT_UNRM_FL              0x00000002  // Record for undelete
  158. #define EXT_COMPR_FL             0x00000004  // Compressed file
  159. #define EXT_SYNC_FL              0x00000008  // Synchronous updates
  160. #define EXT_IMMUTABLE_FL         0x00000010  // Immutable file
  161. #define EXT_APPEND_FL            0x00000020  // Append only
  162. #define EXT_NODUMP_FL            0x00000040  // Do not dump/delete file
  163. #define EXT_NOATIME_FL           0x00000080  // Do not update .i_atime
  164. #define EXT_DIRTY_FL             0x00000100  // Dirty (file is in use?)
  165. #define EXT_COMPRBLK_FL          0x00000200  // Compressed blocks
  166. #define EXT_NOCOMPR_FL           0x00000400  // Access raw compressed data
  167. #define EXT_ECOMPR_FL            0x00000800  // Compression error
  168. #define EXT_BTREE_FL             0x00001000  // B-tree format directory
  169. #define EXT_INDEX_FL             0x00010000  // Hash indexed directory
  170.  
  171. typedef struct {
  172.   unsigned inodes_count;
  173.   unsigned blocks_count;
  174.   unsigned r_blocks_count;
  175.   unsigned free_blocks_count;
  176.   unsigned free_inodes_count;
  177.   unsigned first_data_block;
  178.   unsigned log_block_size;
  179.   unsigned log_frag_size;
  180.   unsigned blocks_per_group;
  181.   unsigned frags_per_group;
  182.   unsigned inodes_per_group;
  183.   unsigned mtime;
  184.   unsigned wtime;
  185.   unsigned short mnt_count;
  186.   unsigned short max_mnt_count;
  187.   unsigned short magic;
  188.   unsigned short state;
  189.   unsigned short errors;
  190.   unsigned short minor_rev_level;
  191.   unsigned lastcheck;
  192.   unsigned checkinterval;
  193.   unsigned creator_os;
  194.   unsigned rev_level;
  195.   unsigned short def_resuid;
  196.   unsigned short def_resgid;
  197.   // EXT2_DYNAMIC_REV Specific
  198.   unsigned first_ino;
  199.   unsigned short inode_size;
  200.   unsigned short block_group_nr;
  201.   unsigned feature_compat;
  202.   unsigned feature_incompat;
  203.   unsigned feature_ro_compat;
  204.   unsigned char uuid[16];
  205.   char volume_name[16];
  206.   unsigned char last_mounted[64];
  207.   unsigned algo_bitmap;
  208.   // Performance Hints
  209.   unsigned char prealloc_blocks;
  210.   unsigned char prealloc_dir_blocks;
  211.   unsigned short alignment;
  212.   // Journaling Support
  213.   unsigned char journal_uuid[16];
  214.   unsigned journal_inum;
  215.   unsigned journal_dev;
  216.   unsigned last_orphan;
  217.   unsigned char padding[788];
  218.  
  219. } __attribute__((packed)) extSuperblock;
  220.  
  221. typedef struct {
  222.   unsigned block_bitmap;
  223.   unsigned inode_bitmap;
  224.   unsigned inode_table;
  225.   unsigned short free_blocks_count;
  226.   unsigned short free_inodes_count;
  227.   unsigned short used_dirs_count;
  228.   unsigned short pad;
  229.   unsigned char reserved[12];
  230.  
  231. } __attribute__((packed)) extGroupDescriptor;
  232.  
  233. typedef struct {
  234.   unsigned short i_mode;
  235.   unsigned short uid;
  236.   unsigned size;
  237.   unsigned atime;
  238.   unsigned ctime;
  239.   unsigned mtime;
  240.   unsigned dtime;
  241.   unsigned short gid;
  242.   unsigned short links_count;
  243.   unsigned blocks;
  244.   unsigned flags;
  245.   unsigned osd1;
  246.   unsigned block[15];
  247.   unsigned generation;
  248.   unsigned file_acl;
  249.   unsigned dir_acl;
  250.   unsigned faddr;
  251.   unsigned char osd2[12];
  252.  
  253. } __attribute__((packed)) extInode;
  254.  
  255. typedef struct {
  256.   unsigned inode;
  257.   unsigned short rec_len;
  258.   unsigned char name_len;
  259.   unsigned char file_type;
  260.   char name[256];
  261.  
  262. } __attribute__((packed)) extDirectoryEntry;
  263.  
  264. #define _EXT_H
  265. #endif
  266.